package com.server.modules.api.web;

import com.google.gson.Gson;
import com.server.modules.api.Base.BaseAppController;
import com.server.modules.api.service.IArticleAPIService;
import com.server.modules.api.vo.AriticalVo;
import com.server.modules.api.vo.BaseQueryVo;
import com.server.modules.api.vo.ContactVo;
import com.server.modules.api.vo.list.ContactList;
import com.server.modules.cms.entity.Article;
import com.server.modules.cms.entity.Category;
import com.server.modules.cms.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Author SilentWolf
 * Date ${DATETIME}
 */
@Controller
@RequestMapping(value = "/api/article")
public class ArticleAPIController extends BaseAppController {

@Resource
private IArticleAPIService articleAPIService;


	@ResponseBody
	@RequestMapping(value = "/getRecentlyPushArticles")
	public BaseQueryVo getRecentlyPushArticles(HttpServletRequest request, String sessionId) {
		BaseQueryVo vo=new BaseQueryVo();
        List<Article> list = articleAPIService.getRecentlyPushArticles();
        if(!CollectionUtils.isEmpty(list)){
            vo.setData(list);
            vo.setRetCode(0);
            vo.setRetMsg("获取成功！");
        }else{
            vo.setRetCode(120);
            vo.setRetMsg("获取失败，没有需要推送的文章！");
        }
        return vo;
	}
    @ResponseBody
    @RequestMapping(value = "/getArticleTypes")
    public BaseQueryVo getArticleTypes(HttpServletRequest request, String sessionId) {
        BaseQueryVo vo=new BaseQueryVo();
        Category ca = new Category();
         List<Category> categoryList=  articleAPIService.getCategory();
        vo.setData(categoryList);
        return vo;
    }

    /**
     * 获取推荐文章
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getRecommendArticles")
    public BaseQueryVo getRecommendArticles(HttpServletRequest request) {
        BaseQueryVo vo=new BaseQueryVo();
        List<Article> list = articleAPIService.getRecommendArticles();
        if(!CollectionUtils.isEmpty(list)){
            vo.setData(list);
            vo.setRetCode(0);
            vo.setRetMsg("获取成功！");
        }else{
            vo.setRetCode(120);
            vo.setRetMsg("未查询到相关数据");
        }
        return vo;
    }
    @ResponseBody
    @RequestMapping(value = "/getArticlesList")
    public BaseQueryVo getArticlesList(HttpServletRequest request,AriticalVo vo ) {
        setPageConfig(vo);
        List<AriticalVo> list = articleAPIService.getArticles(vo);
        if(!CollectionUtils.isEmpty(list)){
            vo.setData(list);
            vo.setRetCode(0);
            vo.setRetMsg("获取成功！");
        }else{
            vo.setRetCode(120);
            vo.setRetMsg("文章列表为空！");
        }
        return vo;
    }

}
